package com.black.common.upload.serializer;

import com.black.common.upload.config.MyOosConfig;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.io.IOException;

/**
 * @author linwenfeng
 */
public class ImgJsonDeserializer extends JsonDeserializer<String> {

    @Override
    public String deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        if (ObjectUtils.isEmpty(jsonParser)) {
            return null;
        }
        String text = jsonParser.getText();
        if (StringUtils.isEmpty(text)){
            return null;
        }
        if (text.contains(MyOosConfig.domain)){
            return text.replaceAll(MyOosConfig.domain,"");
        }
        return text;
    }
}
